#
# arch/arm64/Makefile
#
# This file is included by the global makefile so that you can add your own
# architecture-specific flags and dependencies.
#
# This file is subject to the terms and conditions of the GNU General Public
# License.  See the file "COPYING" in the main directory of this archive
# for more details.
#
# Copyright (C) 1995-2001 by Russell King

LDFLAGS_photon	:=-p --no-undefined -X
CPPFLAGS_photon.lds = -DTEXT_OFFSET=$(TEXT_OFFSET)
OBJCOPYFLAGS	:=-O binary -R .note -R .note.gnu.build-id -R .comment -S
GZFLAGS		:=-9

KBUILD_DEFCONFIG := defconfig

KBUILD_CFLAGS	+= -fno-pic -Wno-unused-function
ifeq ($(CONFIG_CPU_BIG_ENDIAN), y)
KBUILD_CPPFLAGS	+= -mbig-endian
AS		+= -EB
LD		+= -EB
else
KBUILD_CPPFLAGS	+= -mlittle-endian
AS		+= -EL
LD		+= -EL
endif

CHECKFLAGS	+= 

ifeq ($(CONFIG_CPU_CORTEX_R), y)
KBUILD_CPPFLAGS += -O1 -Wall  -march=armv7-r 
endif

ifeq ($(CONFIG_CPU_CORTEX_M), y)
KBUILD_CPPFLAGS += -O1 -Wall  -march=armv7-m  -mcpu=cortex-m3 -mthumb -Wa,-mimplicit-it=thumb
endif

ifeq ($(CONFIG_ARM64_ERRATUM_843419), y)
KBUILD_CFLAGS_MODULE	+= -mcmodel=large
endif

# Default value

ifeq ($(CONFIG_CPU_CORTEX_R), y)
head-y		:= arch/arm/kernel/head_v7r.o
endif

ifeq ($(CONFIG_CPU_CORTEX_M), y)
head-y		:= arch/arm/kernel/head.o
endif


# The byte offset of the kernel image in RAM from the start of RAM.
ifeq ($(CONFIG_ARM64_RANDOMIZE_TEXT_OFFSET), y)
TEXT_OFFSET := $(shell awk 'BEGIN {srand(); printk "0x%03x000\n", int(512 * rand())}')
else
TEXT_OFFSET := 0x0
endif

export	TEXT_OFFSET GZFLAGS

core-y		+= arch/arm/kernel/
libs-y		:= arch/arm/lib/ $(libs-y)

# The machine dir
ifeq ($(CONFIG_ARCH_XILINX_CORTEXR5), y)
core-y  += arch/arm/mach-zynqmp_r5/
endif
ifeq ($(CONFIG_ARCH_MPS2_CORTEXM3), y)
core-y  += arch/arm/mach-mps2_m3/
endif

# Default target when executing plain make
ifeq ($(CONFIG_BUILD_ARM64_APPENDED_DTB_IMAGE),y)
KBUILD_IMAGE	:= Image.gz-dtb
else
KBUILD_IMAGE	:= Image.gz
endif

all:	$(KBUILD_IMAGE)

boot := arch/arm/boot

Image Image.gz: photon
	$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@

zinstall install: photon
	$(Q)$(MAKE) $(build)=$(boot) $@

Image.gz-dtb: photon scripts
	$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@

PHONY += vdso_install
vdso_install:
	$(Q)$(MAKE) $(build)=arch/arm/kernel/vdso $@

# We use MRPROPER_FILES and CLEAN_FILES now
archclean:
	$(Q)$(MAKE) $(clean)=$(boot)

define archhelp
  echo  '* Image.gz      - Compressed kernel image (arch/$(ARCH)/boot/Image.gz)'
  echo  '  Image         - Uncompressed kernel image (arch/$(ARCH)/boot/Image)'
  echo  '  install       - Install uncompressed kernel'
  echo  '  zinstall      - Install compressed kernel'
  echo  '                  Install using (your) ~/bin/installkernel or'
  echo  '                  (distribution) /sbin/installkernel or'
  echo  '                  install to $$(INSTALL_PATH) and run lilo'
endef
